//
//  LGPatientNavigationView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/25.
//

#import "LGPatientNavigationView.h"

@interface LGPatientNavigationView()
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;

@end

@implementation LGPatientNavigationView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setPatientDic:(NSDictionary *)patientDic{
    _patientDic = patientDic;
    NSString *nameStr = LGNSString(patientDic[@"realname"]);
    self.nameLabel.text = nameStr;
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@岁",patientDic[@"gender"],patientDic[@"age"]];
    CGFloat nameW = [nameStr textWidthWithFont:LGFontWeight(16, UIFontWeightSemibold) maxHeight:MAXFLOAT];
    nameW = (nameW<50)?50:nameW;
    [self.nameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(nameW+2));
    }];
    
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self addSubview:self.backButton];
    [self addSubview:self.nameLabel];
    [self addSubview:self.ageLabel];
    [self addSubview:self.tipView];
    [self addSubview:self.checkButton];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(statusBarHeight+5);
        make.width.equalTo(@(60));
        make.centerX.equalTo(self);
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(1);
        make.centerX.equalTo(self);
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel.mas_bottom);
        make.width.height.equalTo(@(12));
    }];
    [self.checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.nameLabel);
        make.right.equalTo(self.tipView);
        make.bottom.equalTo(self.ageLabel);
    }];
}
-(UIButton *)backButton{
    if(!_backButton){
        _backButton = [UIButton buttonWithImage:@"navBack" selectImage:@"navBack"];
        _backButton.frame = CGRectMake(0, statusBarHeight, 44, 44);
    }
    return _backButton;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(13) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _ageLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"patientTip"]];
    }
    return _tipView;
}

-(UIButton *)checkButton{
    if(!_checkButton){
        _checkButton = [UIButton buttonWithType:UIButtonTypeSystem];
    }
    return _checkButton;
}

@end
